"""
CREATE TABLE `analysis` (
  `cid` int(11) NOT NULL AUTO_INCREMENT,
  `uid` varchar(50) DEFAULT NULL,
  `timestamp` bigint(20) DEFAULT NULL,
  `isreal` tinyint(1) DEFAULT NULL,
  `drinking_rule` tinyint(1) DEFAULT NULL,
  `breakfast_rule` tinyint(1) DEFAULT NULL,
  `threeMeals_rule` tinyint(1) DEFAULT NULL,
  `exercise_rule` tinyint(1) DEFAULT NULL,
  `sevenHours_rule` tinyint(1) DEFAULT NULL,
  `yoyoSleep_rule` tinyint(1) DEFAULT NULL,
  `socializing_rule` tinyint(1) DEFAULT NULL,
  `spiritual_rule` tinyint(1) DEFAULT NULL,
  `study_rule` tinyint(1) DEFAULT NULL,
  `work_rule` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`cid`)
) AUTO_INCREMENT=0;
"""

import time
import sqlalchemy
from   sqlalchemy import Column, Integer, String, create_engine
from   sqlalchemy.ext.declarative import declarative_base
from   sqlalchemy.orm import sessionmaker

class Analysis(declarative_base()):
    __tablename__ = "analysis"
    
    cid              = Column(Integer, primary_key=True)
    uid              = Column(String)
    timestamp        = Column(Integer)
    isreal           = Column(Integer)
    drinking_rule    = Column(Integer)
    breakfast_rule   = Column(Integer)
    threeMeals_rule  = Column(Integer)
    exercise_rule    = Column(Integer)
    sevenHours_rule  = Column(Integer)
    yoyoSleep_rule   = Column(Integer)
    socializing_rule = Column(Integer)
    spiritual_rule   = Column(Integer)
    study_rule       = Column(Integer)
    work_rule        = Column(Integer)

    def __init__(self, rules, uid = None, isreal = True):
        timestamp = time.time()
        self.uid = str(timestamp) if uid == None else uid
        self.timestamp = int(timestamp)
        self.isreal = isreal

        self.drinking_rule    = rules['drinking'].result
        self.breakfast_rule   = rules['breakfast'].result
        self.threeMeals_rule  = rules['threeMeals'].result
        self.exercise_rule    = rules['exercise'].result
        self.sevenHours_rule  = rules['sevenHours'].result
        self.yoyoSleep_rule   = rules['yoyoSleep'].result
        self.socializing_rule = rules['socializing'].result
        self.spiritual_rule   = rules['spiritual'].result
        self.study_rule       = rules['study'].result
        self.work_rule        = rules['work'].result
